<%--
  Created by IntelliJ IDEA.
  User: ss
  Date: 2021/12/13
  Time: 14:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>index.jsp</title>
  </head>
  <script>
    function text(){
      // 发送异步请求

      //1.创建xmlHttpreuqst对象,ie浏览器和其他浏览器有不同
      var xmlhttp;
      if(window.XMLHttpRequest){
        //非ie浏览器时
        xmlhttp = new XMLHttpRequest();
      }else if(window.ActiveXObject){
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
      }

      //2.打开连接
      var uname = document.getElementById("uname").value;
      xmlhttp.open("get","/testuname?username="+uname,true)
      // true 表示通过异步
      //3.指定回调函数
      xmlhttp.onreadystatechange = function (){
        //判断状态
        if (xmlhttp.readyState==4){
          // 返回接受的数据
          var res = xmlhttp.responseText;
          document.getElementById("rs").innerHTML = res;
        }
      }
      //4.发送数据
      xmlhttp.send();
    }
  </script>
  <body>
  用户名：<input type="text" id="uname" onblur="text()"><span id="rs"></span>
  </body>
</html>
